﻿using System;

namespace Pyramid.Hardware.Operations
{
    public class FullAdder
    {
        private HalfAdder _firstStage;
        private HalfAdder _secondStage;
        private HalfAdder _carryAdder;

        public FullAdder(ILine lineA, ILine lineB, ILine carryIn)
        {
            if (lineA == null)
                throw new ArgumentNullException("lineA");

            if (lineB == null)
                throw new ArgumentNullException("lineB");

            if (carryIn == null)
                throw new ArgumentNullException("carryIn");

            _firstStage = new HalfAdder(lineA, lineB);
            _secondStage = new HalfAdder(_firstStage.Sum, carryIn);
            _carryAdder = new HalfAdder(_firstStage.Carry, _secondStage.Carry);
        }

        public ILine Sum
        {
            get
            {
                return _secondStage.Sum;
            }
        }

        public ILine Carry
        {
            get
            {
                return _carryAdder.Sum;
            }
        }
    }
}
